var ClubZhiDingUesrRecordWindow = Window.extend({
    _ccsFileName: res.ClubZhiDingUesrRecordWindow_json,
    _userId: null,
    _clubId: null,
    _viewListData: [],         //战绩回放数据
    _originalList: [],
    _selectedWanFaNames: null, //过滤的玩法名称列表
    initWindow: function (clubId, userId) {
        this._clubId = clubId;
        this._userId = userId;

        this.initTableView();
        this._initDropDownMenu();
        this.getRecords(this._userId);
    },

    /**
     * 初始化TableView
     */
    initTableView: function () {
        var nodeContent = this._nodeList['nodeContent'];
        var tableViewSize = nodeContent.getContentSize();
        this._tableView = new cc.TableView(this, cc.size(tableViewSize.width, tableViewSize.height));
        this._tableView.setDelegate(this);
        this._tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        this._tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        this._tableView.setPosition(nodeContent.getPosition());
        nodeContent.getParent().addChild(this._tableView);
    },

    /**
     * 初始化下拉菜单
     * @private
     */
    _initDropDownMenu: function () {
        var config = {
            selectBgRes: res.dropDownMenuTopBack,
            selectBtnRes: res.dropDownMenuBtn,
            menuRes: res.dropDownMenuBack3,
            dataArr: _.keys(club.ClubWanfaFilter),
            normalIndex: 0,
            fontSize: 30,
            selectCallBack: this._dropDownMenuHandler.bind(this)
        };
        this._dropDownMenu = new DropDownMenu(config);
        this._nodeList['menu'].getParent().addChild(this._dropDownMenu);
        this._dropDownMenu.setPosition(this._nodeList['menu'].getPosition());
    },

    /**
     * 请求我得战绩
     */
    getRecords: function (uid) {
        showLoading('加载中...');
        var uri = '/Record/' + app.clubRecordArea + '?uid=' + uid + '&club_id=' + this._clubId;
        var sign = Crypto.MD5('request:' + uri).toString();
        http.get("http://rec.yygameapi.com:56790" + uri + "&sign=" + sign, this._recordsRequestHandler.bind(this));
    },
    _recordsRequestHandler: function (data) {
        hideLoading();
        this._originalList = JSON.parse(data)['data'] || [];
        this._wanfaFilter();
    },

    _dropDownMenuHandler: function (content, index) {
        this._selectedWanFaNames = club.ClubWanfaFilter[content];
        this._wanfaFilter();
    },

    _wanfaFilter: function () {
        this._viewListData = filterMapId(this._selectedWanFaNames, this._originalList);
        this._tableView.reloadData();
    },


    tableCellAtIndex: function (table, idx) {
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('ClubZhiDingUesrRecordItem', cell, this._clubId, this._viewListData[idx]);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell");
            node.setData(this._clubId, this._viewListData[idx]);
        }
        return cell;
    },
    tableCellTouched: function (table, cell) {
        var idx = cell.getIdx();
        var itemData = this._viewListData[idx];
        if (itemData && itemData['result_arr'] && itemData['result_arr'].length > 0) {
            // window.maLayer.addChild(new ZhanjiDetailLayer(itemData['id'], itemData['nickname1'], itemData['nickname2'], itemData['nickname3'], itemData['nickname4'], itemData['result_arr'], itemData, this.club_id));
            ClubDataManager.ClubRecordData = itemData;
            club.openHistoryDetail(this,itemData);
        } else {
            showAlert("尚未产生战绩");
        }
    },
    tableCellSizeForIndex: function (table, idx) {
        return cc.size(963, 140);
    },
    numberOfCellsInTableView: function (table) {
        return this._viewListData.length;
    },

});